/*
 * ProjetoTCC2View.java
 */
package projetotcc2;

import jEDF.Dialog.JEDFHelpDialog;
import jEDF.EDF.EDFFile;
import jEDF.EDF.EDFFileFilter;
import jEDF.EDF.EDFInformationDialog;
import jEDF.EDF.EDFSignalToTextDialog;
import jEDF.Exceptions.UserCancelException;
import jEDF.FFT.FFTExportDialog;
import jEDF.Hypnogram.HypnogramToTextDialog;
import jEDF.Hypnogram.JEDFHypnogram;
import jEDF.Hypnogram.JEDFStagesPanel;
import jEDF.Hypnogram.NewHypnogramDialog;
import jEDF.JEDF.JEDFSignalCaption;
import jEDF.JEDF.Polysomnograph;
import jEDF.Montage.Montage;
import jEDF.Montage.NewMontageDialog;
import jEDF.PreciseScoring.NewPreciseScoringDialog;
import jEDF.PreciseScoring.PreciseScoring;
import jEDF.PreciseScoring.PreciseScoringToTextDialog;
import jEDF.Resources.MyResource_BR;
import java.awt.Component;
import java.awt.DefaultKeyboardFocusManager;
import java.awt.Dimension;
import java.awt.KeyEventPostProcessor;
import java.awt.event.KeyEvent;
import java.io.File;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URI;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.ResourceBundle;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JToggleButton;
import java.util.Calendar;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 * The application's main frame.
 */
public class ProjetoTCC2View extends FrameView {

    public ProjetoTCC2View(SingleFrameApplication app) {
        super(app);

        local = local();

        initComponents();
        initComponentsAfter();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = ProjetoTCC2App.getApplication().getMainFrame();
            aboutBox = new ProjetoTCC2AboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        ProjetoTCC2App.getApplication().show(aboutBox);
    }

    @Action
    public void openEDFFile() {
        File diretorio = jFileChooser1.getCurrentDirectory();


        try {
            URI uri = new URI(local + "/jEDF.conf");
            File file = new File(uri);
            FileInputStream filein = new FileInputStream(file);
            ObjectInputStream input = new ObjectInputStream(filein);
            diretorio = (File) input.readObject();
            input.close();
        } catch (Exception e) {
        }

        jFileChooser1.setCurrentDirectory(diretorio);

//        ResourceMap resourceMap = getResourceMap();

//        JFileChooser chooser = new JFileChooser(resourceMap.getString("local"));
        int returnVal = jFileChooser1.showOpenDialog(null);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            openFile(jFileChooser1.getSelectedFile());

            try {
                URI uri = new URI(local + "/jEDF.conf");
                File file = new File(uri);
                file.createNewFile();
                FileOutputStream fileout = new FileOutputStream(file);
                ObjectOutputStream output = new ObjectOutputStream(fileout);
                output.writeObject(jFileChooser1.getSelectedFile().getParentFile());
                output.close();
            } catch (Exception e) {
//                JOptionPane.showMessageDialog(null, e);
                e.printStackTrace();
                System.out.println(local);
            }

        }
    }

    public static String getLocalizedString(String string) {
        return resource.getString(string);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        initComponentsCustom();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        propriedadesMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        opcoesMenu = new javax.swing.JMenu();
        SnapToTicksMenu = new javax.swing.JCheckBoxMenuItem();
        antiAliasingMenu = new javax.swing.JCheckBoxMenuItem();
        InvertedMenu = new javax.swing.JCheckBoxMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        hipnogramaMenu = new javax.swing.JMenu();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        scoringMenu = new javax.swing.JMenu();
        salvarScoringMenu = new javax.swing.JMenuItem();
        carregarScoringMenu = new javax.swing.JMenuItem();
        fecharScoringMenu = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        jMenuItem9 = new javax.swing.JMenuItem();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        Status = new javax.swing.JLabel();
        View = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        exibirTab = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        fim = new javax.swing.JButton();
        anterior = new javax.swing.JButton();
        proximo = new javax.swing.JButton();
        jComboBox1 = polysomnograph.getEpochDurationComboBox();
        inicio = new javax.swing.JButton();
        play = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        visualizacaoPainel = new javax.swing.JPanel();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        FerramentasTab = new javax.swing.JPanel();
        Estatatisticas = new javax.swing.JPanel();
        DesvioPadraoLabel = new javax.swing.JLabel();
        DesvioPadrao = new javax.swing.JTextField();
        MediaAritimeticaLabel = new javax.swing.JLabel();
        MediaAritmetica = new javax.swing.JTextField();
        Variancia = new javax.swing.JTextField();
        VarianciaLabel = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        MontagemComboBox = new javax.swing.JComboBox();
        jButton10 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        MontagemLabel = new javax.swing.JLabel();
        transformadasPainel = new javax.swing.JPanel();
        FFTbutton = new javax.swing.JButton();
        FWTbutton = new javax.swing.JButton();
        DWTbutton = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        hypnogramaTab = new javax.swing.JPanel();
        novoHypnogramaPanel = new javax.swing.JPanel();
        jButton4 = new javax.swing.JButton();
        StagesPainel = new javax.swing.JPanel();
        HypnogramaPainel = hypnogram;
        scoringTab = new javax.swing.JPanel();
        preciseScoringPanel = preciseScoring;
        novoPreciseScoringPanel = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel7 = signalCaption;
        jPanel4 = polysomnograph;
        jSlider1 = polysomnograph.getNavigationSlider();
        Montagens = new javax.swing.ButtonGroup();
        jMenuItem10 = new javax.swing.JMenuItem();
        jFileChooser1 = new javax.swing.JFileChooser();

        menuBar.setName("menuBar"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(projetotcc2.ProjetoTCC2App.class).getContext().getResourceMap(ProjetoTCC2View.class);
        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(projetotcc2.ProjetoTCC2App.class).getContext().getActionMap(ProjetoTCC2View.class, this);
        jMenuItem1.setAction(actionMap.get("openEDFFile")); // NOI18N
        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        fileMenu.add(jMenuItem1);

        jMenuItem3.setAction(actionMap.get("limpar")); // NOI18N
        jMenuItem3.setText(resourceMap.getString("jMenuItem3.text")); // NOI18N
        jMenuItem3.setName("jMenuItem3"); // NOI18N
        fileMenu.add(jMenuItem3);

        propriedadesMenuItem.setAction(actionMap.get("Info")); // NOI18N
        propriedadesMenuItem.setText(resourceMap.getString("propriedadesMenuItem.text")); // NOI18N
        propriedadesMenuItem.setName("propriedadesMenuItem"); // NOI18N
        fileMenu.add(propriedadesMenuItem);

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        opcoesMenu.setText(resourceMap.getString("opcoesMenu.text")); // NOI18N
        opcoesMenu.setName("opcoesMenu"); // NOI18N

        SnapToTicksMenu.setText(resourceMap.getString("SnapToTicksMenu.text")); // NOI18N
        SnapToTicksMenu.setName("SnapToTicksMenu"); // NOI18N
        SnapToTicksMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SnapToTicksMenuActionPerformed(evt);
            }
        });
        opcoesMenu.add(SnapToTicksMenu);

        antiAliasingMenu.setText(resourceMap.getString("antiAliasingMenu.text")); // NOI18N
        antiAliasingMenu.setName("antiAliasingMenu"); // NOI18N
        antiAliasingMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                antiAliasingMenuActionPerformed(evt);
            }
        });
        opcoesMenu.add(antiAliasingMenu);

        InvertedMenu.setText(resourceMap.getString("InvertedMenu.text")); // NOI18N
        InvertedMenu.setName("InvertedMenu"); // NOI18N
        InvertedMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                InvertedMenuActionPerformed(evt);
            }
        });
        opcoesMenu.add(InvertedMenu);

        jMenuItem4.setAction(actionMap.get("exportarEdfParaTexto")); // NOI18N
        jMenuItem4.setText(resourceMap.getString("jMenuItem4.text")); // NOI18N
        jMenuItem4.setName("jMenuItem4"); // NOI18N
        opcoesMenu.add(jMenuItem4);

        jMenuItem5.setAction(actionMap.get("exportarAnaliseFFT")); // NOI18N
        jMenuItem5.setText(resourceMap.getString("jMenuItem5.text")); // NOI18N
        jMenuItem5.setName("jMenuItem5"); // NOI18N
        opcoesMenu.add(jMenuItem5);

        menuBar.add(opcoesMenu);

        hipnogramaMenu.setText(resourceMap.getString("hipnogramaMenu.text")); // NOI18N
        hipnogramaMenu.setName("hipnogramaMenu"); // NOI18N

        jMenuItem7.setAction(actionMap.get("salvarHypnograma")); // NOI18N
        jMenuItem7.setText(resourceMap.getString("jMenuItem7.text")); // NOI18N
        jMenuItem7.setName("jMenuItem7"); // NOI18N
        hipnogramaMenu.add(jMenuItem7);

        jMenuItem8.setAction(actionMap.get("carregarHypnograma")); // NOI18N
        jMenuItem8.setText(resourceMap.getString("jMenuItem8.text")); // NOI18N
        jMenuItem8.setName("jMenuItem8"); // NOI18N
        hipnogramaMenu.add(jMenuItem8);

        jMenuItem6.setAction(actionMap.get("fecharHypnograma")); // NOI18N
        jMenuItem6.setText(resourceMap.getString("jMenuItem6.text")); // NOI18N
        jMenuItem6.setName("jMenuItem6"); // NOI18N
        hipnogramaMenu.add(jMenuItem6);

        menuBar.add(hipnogramaMenu);

        scoringMenu.setText(resourceMap.getString("scoringMenu.text")); // NOI18N
        scoringMenu.setEnabled(false);
        scoringMenu.setName("scoringMenu"); // NOI18N

        salvarScoringMenu.setAction(actionMap.get("salvarScoring")); // NOI18N
        salvarScoringMenu.setText(resourceMap.getString("salvarScoringMenu.text")); // NOI18N
        salvarScoringMenu.setName("salvarScoringMenu"); // NOI18N
        scoringMenu.add(salvarScoringMenu);

        carregarScoringMenu.setAction(actionMap.get("carregarScoring")); // NOI18N
        carregarScoringMenu.setText(resourceMap.getString("carregarScoringMenu.text")); // NOI18N
        carregarScoringMenu.setName("carregarScoringMenu"); // NOI18N
        scoringMenu.add(carregarScoringMenu);

        fecharScoringMenu.setAction(actionMap.get("fecharScoring")); // NOI18N
        fecharScoringMenu.setText(resourceMap.getString("fecharScoringMenu.text")); // NOI18N
        fecharScoringMenu.setName("fecharScoringMenu"); // NOI18N
        scoringMenu.add(fecharScoringMenu);

        menuBar.add(scoringMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        jMenuItem9.setAction(actionMap.get("ajudaAtalhosDoTeclado")); // NOI18N
        jMenuItem9.setText(resourceMap.getString("jMenuItem9.text")); // NOI18N
        jMenuItem9.setName("jMenuItem9"); // NOI18N
        helpMenu.add(jMenuItem9);

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        Status.setText(resourceMap.getString("Status.text")); // NOI18N
        Status.setName("Status"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
                .addContainerGap(89, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(statusPanelLayout.createSequentialGroup()
                        .addComponent(statusMessageLabel)
                        .addGap(698, 698, 698)
                        .addComponent(statusAnimationLabel))
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 797, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Status, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                .addGap(746, 746, 746))
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(statusPanelLayout.createSequentialGroup()
                        .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(statusMessageLabel)
                            .addComponent(statusAnimationLabel))
                        .addGap(3, 3, 3))
                    .addGroup(statusPanelLayout.createSequentialGroup()
                        .addComponent(Status)
                        .addContainerGap())))
        );

        View.setName("View"); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N
        jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jTabbedPane1StateChanged(evt);
            }
        });

        exibirTab.setName("exibirTab"); // NOI18N

        jPanel5.setName("jPanel5"); // NOI18N

        fim.setAction(actionMap.get("goToLasttRecord")); // NOI18N
        fim.setText(resourceMap.getString("fim.text")); // NOI18N
        fim.setName("fim"); // NOI18N

        anterior.setAction(actionMap.get("goToPrevRecord")); // NOI18N
        anterior.setName("anterior"); // NOI18N

        proximo.setAction(actionMap.get("goToNextRecord")); // NOI18N
        proximo.setText(resourceMap.getString("proximo.text")); // NOI18N
        proximo.setName("proximo"); // NOI18N

        jComboBox1.setModel(polysomnograph.getEpochDurationComboBox().getModel());
        jComboBox1.setToolTipText(resourceMap.getString("jComboBox1.toolTipText")); // NOI18N
        jComboBox1.setName("jComboBox1"); // NOI18N

        inicio.setAction(actionMap.get("goToFirstRecord")); // NOI18N
        inicio.setBorderPainted(false);
        inicio.setName("inicio"); // NOI18N

        play.setAction(actionMap.get("Play")); // NOI18N
        play.setText(resourceMap.getString("play.text")); // NOI18N
        play.setName("play"); // NOI18N

        jButton1.setAction(actionMap.get("goToPrevSec")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jButton9.setAction(actionMap.get("goToNextSec")); // NOI18N
        jButton9.setText(resourceMap.getString("jButton9.text")); // NOI18N
        jButton9.setName("jButton9"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(inicio, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(anterior, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(proximo, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(fim, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(50, 50, 50)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(play, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jComboBox1, 0, 127, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(inicio, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(play))
                    .addComponent(fim, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(anterior, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(proximo, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(182, 182, 182))
        );

        visualizacaoPainel.setName("visualizacaoPainel"); // NOI18N

        jButton13.setAction(actionMap.get("menosAmpl")); // NOI18N
        jButton13.setText(resourceMap.getString("jButton13.text")); // NOI18N
        jButton13.setName("jButton13"); // NOI18N

        jButton14.setAction(actionMap.get("resetAmpl")); // NOI18N
        jButton14.setText(resourceMap.getString("jButton14.text")); // NOI18N
        jButton14.setName("jButton14"); // NOI18N

        jButton8.setAction(actionMap.get("menosZoom")); // NOI18N
        jButton8.setText(resourceMap.getString("jButton8.text")); // NOI18N
        jButton8.setName("jButton8"); // NOI18N

        jButton7.setAction(actionMap.get("resetZoom")); // NOI18N
        jButton7.setName("jButton7"); // NOI18N

        jButton12.setAction(actionMap.get("maisAmpl")); // NOI18N
        jButton12.setText(resourceMap.getString("jButton12.text")); // NOI18N
        jButton12.setName("jButton12"); // NOI18N

        jButton6.setAction(actionMap.get("maisZoom")); // NOI18N
        jButton6.setText(resourceMap.getString("jButton6.text")); // NOI18N
        jButton6.setName("jButton6"); // NOI18N

        javax.swing.GroupLayout visualizacaoPainelLayout = new javax.swing.GroupLayout(visualizacaoPainel);
        visualizacaoPainel.setLayout(visualizacaoPainelLayout);
        visualizacaoPainelLayout.setHorizontalGroup(
            visualizacaoPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(visualizacaoPainelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(visualizacaoPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(visualizacaoPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(visualizacaoPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        visualizacaoPainelLayout.setVerticalGroup(
            visualizacaoPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(visualizacaoPainelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(visualizacaoPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(visualizacaoPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout exibirTabLayout = new javax.swing.GroupLayout(exibirTab);
        exibirTab.setLayout(exibirTabLayout);
        exibirTabLayout.setHorizontalGroup(
            exibirTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(exibirTabLayout.createSequentialGroup()
                .addComponent(visualizacaoPainel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(220, Short.MAX_VALUE))
        );
        exibirTabLayout.setVerticalGroup(
            exibirTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(visualizacaoPainel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab(resourceMap.getString("exibirTab.TabConstraints.tabTitle"), exibirTab); // NOI18N

        FerramentasTab.setName("FerramentasTab"); // NOI18N

        Estatatisticas.setName("Estatatisticas"); // NOI18N

        DesvioPadraoLabel.setText(resourceMap.getString("DesvioPadraoLabel.text")); // NOI18N
        DesvioPadraoLabel.setName("DesvioPadraoLabel"); // NOI18N

        DesvioPadrao.setEditable(false);
        DesvioPadrao.setText(resourceMap.getString("DesvioPadrao.text")); // NOI18N
        DesvioPadrao.setToolTipText(resourceMap.getString("DesvioPadrao.toolTipText")); // NOI18N
        DesvioPadrao.setName("DesvioPadrao"); // NOI18N

        MediaAritimeticaLabel.setText(resourceMap.getString("MediaAritimeticaLabel.text")); // NOI18N
        MediaAritimeticaLabel.setName("MediaAritimeticaLabel"); // NOI18N

        MediaAritmetica.setEditable(false);
        MediaAritmetica.setToolTipText(resourceMap.getString("MediaAritmetica.toolTipText")); // NOI18N
        MediaAritmetica.setName("MediaAritmetica"); // NOI18N

        Variancia.setEditable(false);
        Variancia.setToolTipText(resourceMap.getString("Variancia.toolTipText")); // NOI18N
        Variancia.setName("Variancia"); // NOI18N

        VarianciaLabel.setText(resourceMap.getString("VarianciaLabel.text")); // NOI18N
        VarianciaLabel.setName("VarianciaLabel"); // NOI18N

        javax.swing.GroupLayout EstatatisticasLayout = new javax.swing.GroupLayout(Estatatisticas);
        Estatatisticas.setLayout(EstatatisticasLayout);
        EstatatisticasLayout.setHorizontalGroup(
            EstatatisticasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(EstatatisticasLayout.createSequentialGroup()
                .addContainerGap(10, Short.MAX_VALUE)
                .addGroup(EstatatisticasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(EstatatisticasLayout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(DesvioPadraoLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DesvioPadrao))
                    .addGroup(EstatatisticasLayout.createSequentialGroup()
                        .addGroup(EstatatisticasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(VarianciaLabel)
                            .addComponent(MediaAritimeticaLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(EstatatisticasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(Variancia)
                            .addComponent(MediaAritmetica, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        EstatatisticasLayout.setVerticalGroup(
            EstatatisticasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, EstatatisticasLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(EstatatisticasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(DesvioPadrao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DesvioPadraoLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(EstatatisticasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(MediaAritmetica, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(MediaAritimeticaLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(EstatatisticasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Variancia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(VarianciaLabel))
                .addContainerGap())
        );

        jPanel6.setName("jPanel6"); // NOI18N

        MontagemComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "nenhuma montagem" }));
        MontagemComboBox.setToolTipText(resourceMap.getString("MontagemComboBox.toolTipText")); // NOI18N
        MontagemComboBox.setName("MontagemComboBox"); // NOI18N
        MontagemComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MontagemComboBoxActionPerformed(evt);
            }
        });

        jButton10.setAction(actionMap.get("removerMontagem")); // NOI18N
        jButton10.setText(resourceMap.getString("jButton10.text")); // NOI18N
        jButton10.setToolTipText(resourceMap.getString("jButton10.toolTipText")); // NOI18N
        jButton10.setName("jButton10"); // NOI18N

        jButton2.setAction(actionMap.get("assignNewMontage")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setToolTipText(resourceMap.getString("jButton2.toolTipText")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        MontagemLabel.setText(resourceMap.getString("MontagemLabel.text")); // NOI18N
        MontagemLabel.setName("MontagemLabel"); // NOI18N

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(MontagemLabel)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton10))
                    .addComponent(MontagemComboBox, 0, 138, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(MontagemLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(MontagemComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(25, Short.MAX_VALUE))
        );

        transformadasPainel.setName("transformadasPainel"); // NOI18N

        FFTbutton.setText(resourceMap.getString("FFTbutton.text")); // NOI18N
        FFTbutton.setToolTipText(resourceMap.getString("FFTbutton.toolTipText")); // NOI18N
        FFTbutton.setName("FFTbutton"); // NOI18N
        FFTbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FFTbuttonActionPerformed(evt);
            }
        });

        FWTbutton.setVisible(false);
        FWTbutton.setAction(actionMap.get("FWTCoiflet")); // NOI18N
        FWTbutton.setText(resourceMap.getString("FWTbutton.text")); // NOI18N
        FWTbutton.setToolTipText(resourceMap.getString("FWTbutton.toolTipText")); // NOI18N
        FWTbutton.setName("FWTbutton"); // NOI18N

        DWTbutton.setVisible(false);
        DWTbutton.setAction(actionMap.get("DWTCoiflet")); // NOI18N
        DWTbutton.setText(resourceMap.getString("DWTbutton.text")); // NOI18N
        DWTbutton.setToolTipText(resourceMap.getString("DWTbutton.toolTipText")); // NOI18N
        DWTbutton.setName("DWTbutton"); // NOI18N

        jButton5.setAction(actionMap.get("Wavelet")); // NOI18N
        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N

        jButton11.setAction(actionMap.get("WaveletDaubechies")); // NOI18N
        jButton11.setText(resourceMap.getString("jButton11.text")); // NOI18N
        jButton11.setName("jButton11"); // NOI18N

        javax.swing.GroupLayout transformadasPainelLayout = new javax.swing.GroupLayout(transformadasPainel);
        transformadasPainel.setLayout(transformadasPainelLayout);
        transformadasPainelLayout.setHorizontalGroup(
            transformadasPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(transformadasPainelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(transformadasPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(transformadasPainelLayout.createSequentialGroup()
                        .addComponent(FFTbutton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(FWTbutton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DWTbutton))
                    .addGroup(transformadasPainelLayout.createSequentialGroup()
                        .addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton11)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        transformadasPainelLayout.setVerticalGroup(
            transformadasPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(transformadasPainelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(transformadasPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(FFTbutton)
                    .addComponent(FWTbutton)
                    .addComponent(DWTbutton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(transformadasPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5)
                    .addComponent(jButton11))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout FerramentasTabLayout = new javax.swing.GroupLayout(FerramentasTab);
        FerramentasTab.setLayout(FerramentasTabLayout);
        FerramentasTabLayout.setHorizontalGroup(
            FerramentasTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(FerramentasTabLayout.createSequentialGroup()
                .addComponent(transformadasPainel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Estatatisticas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(135, Short.MAX_VALUE))
        );
        FerramentasTabLayout.setVerticalGroup(
            FerramentasTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(transformadasPainel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(Estatatisticas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab(resourceMap.getString("FerramentasTab.TabConstraints.tabTitle"), FerramentasTab); // NOI18N

        hypnogramaTab.setEnabled(false);
        hypnogramaTab.setName("hypnogramaTab"); // NOI18N

        novoHypnogramaPanel.setName("novoHypnogramaPanel"); // NOI18N

        jButton4.setAction(actionMap.get("novoHypnograma")); // NOI18N
        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N

        javax.swing.GroupLayout novoHypnogramaPanelLayout = new javax.swing.GroupLayout(novoHypnogramaPanel);
        novoHypnogramaPanel.setLayout(novoHypnogramaPanelLayout);
        novoHypnogramaPanelLayout.setHorizontalGroup(
            novoHypnogramaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(novoHypnogramaPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton4)
                .addContainerGap(25, Short.MAX_VALUE))
        );
        novoHypnogramaPanelLayout.setVerticalGroup(
            novoHypnogramaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(novoHypnogramaPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton4)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        StagesPainel.setName("StagesPainel"); // NOI18N
        StagesPainel.setLayout(new java.awt.GridLayout(1, 8));

        HypnogramaPainel.show(false);
        HypnogramaPainel.setName("HypnogramaPainel"); // NOI18N

        javax.swing.GroupLayout HypnogramaPainelLayout = new javax.swing.GroupLayout(HypnogramaPainel);
        HypnogramaPainel.setLayout(HypnogramaPainelLayout);
        HypnogramaPainelLayout.setHorizontalGroup(
            HypnogramaPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 792, Short.MAX_VALUE)
        );
        HypnogramaPainelLayout.setVerticalGroup(
            HypnogramaPainelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 85, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout hypnogramaTabLayout = new javax.swing.GroupLayout(hypnogramaTab);
        hypnogramaTab.setLayout(hypnogramaTabLayout);
        hypnogramaTabLayout.setHorizontalGroup(
            hypnogramaTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(StagesPainel, javax.swing.GroupLayout.DEFAULT_SIZE, 792, Short.MAX_VALUE)
            .addComponent(HypnogramaPainel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(hypnogramaTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(hypnogramaTabLayout.createSequentialGroup()
                    .addComponent(novoHypnogramaPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(636, Short.MAX_VALUE)))
        );
        hypnogramaTabLayout.setVerticalGroup(
            hypnogramaTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, hypnogramaTabLayout.createSequentialGroup()
                .addComponent(HypnogramaPainel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(StagesPainel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(hypnogramaTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(hypnogramaTabLayout.createSequentialGroup()
                    .addComponent(novoHypnogramaPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(46, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab(resourceMap.getString("hypnogramaTab.TabConstraints.tabTitle"), hypnogramaTab); // NOI18N

        scoringTab.setName("scoringTab"); // NOI18N

        preciseScoringPanel.show(false);
        preciseScoringPanel.setName("preciseScoringPanel"); // NOI18N

        javax.swing.GroupLayout preciseScoringPanelLayout = new javax.swing.GroupLayout(preciseScoringPanel);
        preciseScoringPanel.setLayout(preciseScoringPanelLayout);
        preciseScoringPanelLayout.setHorizontalGroup(
            preciseScoringPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 792, Short.MAX_VALUE)
        );
        preciseScoringPanelLayout.setVerticalGroup(
            preciseScoringPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 91, Short.MAX_VALUE)
        );

        novoPreciseScoringPanel.setName("novoPreciseScoringPanel"); // NOI18N

        jButton3.setAction(actionMap.get("novoPreciseScoring")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N

        javax.swing.GroupLayout novoPreciseScoringPanelLayout = new javax.swing.GroupLayout(novoPreciseScoringPanel);
        novoPreciseScoringPanel.setLayout(novoPreciseScoringPanelLayout);
        novoPreciseScoringPanelLayout.setHorizontalGroup(
            novoPreciseScoringPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(novoPreciseScoringPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        novoPreciseScoringPanelLayout.setVerticalGroup(
            novoPreciseScoringPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(novoPreciseScoringPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout scoringTabLayout = new javax.swing.GroupLayout(scoringTab);
        scoringTab.setLayout(scoringTabLayout);
        scoringTabLayout.setHorizontalGroup(
            scoringTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 792, Short.MAX_VALUE)
            .addGroup(scoringTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(preciseScoringPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(scoringTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(scoringTabLayout.createSequentialGroup()
                    .addComponent(novoPreciseScoringPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(623, Short.MAX_VALUE)))
        );
        scoringTabLayout.setVerticalGroup(
            scoringTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 91, Short.MAX_VALUE)
            .addGroup(scoringTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(preciseScoringPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(scoringTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(scoringTabLayout.createSequentialGroup()
                    .addComponent(novoPreciseScoringPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(46, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab(resourceMap.getString("scoringTab.TabConstraints.tabTitle"), scoringTab); // NOI18N

        jTabbedPane1.setSelectedIndex(0);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 797, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jScrollPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jSplitPane1.setDividerLocation(50);
        jSplitPane1.setDividerSize(2);
        jSplitPane1.setName("jSplitPane1"); // NOI18N

        jPanel7.setName("jPanel7"); // NOI18N

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 49, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 421, Short.MAX_VALUE)
        );

        jSplitPane1.setLeftComponent(jPanel7);

        jPanel4.setName("jPanel4"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 775, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 421, Short.MAX_VALUE)
        );

        jSplitPane1.setRightComponent(jPanel4);
        jPanel4.addPropertyChangeListener(new dropFile(jPanel4, this));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 828, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE)
        );

        jScrollPane1.setViewportView(jPanel1);

        jSlider1.setName("jSlider1"); // NOI18N

        javax.swing.GroupLayout ViewLayout = new javax.swing.GroupLayout(View);
        View.setLayout(ViewLayout);
        ViewLayout.setHorizontalGroup(
            ViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSlider1, javax.swing.GroupLayout.DEFAULT_SIZE, 797, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 797, Short.MAX_VALUE)
        );
        ViewLayout.setVerticalGroup(
            ViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ViewLayout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jMenuItem10.setAction(actionMap.get("ajudaAtalhosDoTeclado")); // NOI18N
        jMenuItem10.setText(resourceMap.getString("jMenuItem9.text")); // NOI18N
        jMenuItem10.setName("jMenuItem9"); // NOI18N

        jFileChooser1.setDialogTitle(resourceMap.getString("Filechooser.dialogTitle")); // NOI18N
        jFileChooser1.setFileFilter(new EDFFileFilter(new String[]{"edf","hyp","rec"}, getLocalizedString("EDF files")));
        jFileChooser1.setName("Filechooser"); // NOI18N

        setComponent(View);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void antiAliasingMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_antiAliasingMenuActionPerformed
        if (getEdfFile() != null) {
            polysomnograph.setInterpolated(antiAliasingMenu.getState());
        } else {
            antiAliasingMenu.setState(false);
        }
    }//GEN-LAST:event_antiAliasingMenuActionPerformed

    private void InvertedMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_InvertedMenuActionPerformed
        if (getEdfFile() != null) {
            polysomnograph.setAllGraphsInverted(InvertedMenu.getState());
        } else {
            InvertedMenu.setState(false);
        }
    }//GEN-LAST:event_InvertedMenuActionPerformed

    private void MontagemComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MontagemComboBoxActionPerformed
        try {
            if (MontagemComboBox.getSelectedIndex() == 0) {
                loadDefaultmontage();
            } else {
                polysomnograph.loadMontage(getMontages().get(MontagemComboBox.getSelectedIndex() - 1));
            }
        } catch (ArrayIndexOutOfBoundsException ar) {
            loadDefaultmontage();
        }
}//GEN-LAST:event_MontagemComboBoxActionPerformed

    private void FFTbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FFTbuttonActionPerformed
        polysomnograph.showfft();
}//GEN-LAST:event_FFTbuttonActionPerformed

    private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane1StateChanged
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(projetotcc2.ProjetoTCC2App.class).getContext().getResourceMap(ProjetoTCC2View.class);
        if (jTabbedPane1.getTitleAt(jTabbedPane1.getSelectedIndex()).equalsIgnoreCase(resourceMap.getString("scoringTab.TabConstraints.tabTitle"))) {
            if (!hypnogram.isCleared()) {
                if (preciseScoring.isCleared()) {
//                jTabbedPane1.setSelectedIndex(2);
                    novoPreciseScoringPanel.show(true);
                    preciseScoringPanel.show(false);
                } else {
                    novoPreciseScoringPanel.show(false);
                    preciseScoringPanel.show(true);
                }
                scoringMenu.setEnabled(true);
                scoringMenu.show(true);
            } else {
                jTabbedPane1.setSelectedIndex(2);
            }
        } else {
            scoringMenu.setEnabled(false);
            scoringMenu.show(false);
        }
        if (jTabbedPane1.getTitleAt(jTabbedPane1.getSelectedIndex()).equalsIgnoreCase(resourceMap.getString("hypnogramaTab.TabConstraints.tabTitle"))) {
//            if (getEdfFile() != null) {
            HypnogramaPainel.show(true);
            StagesPainel.show(true);
            if (hypnogram.isCleared()) {
//                jTabbedPane1.setSelectedIndex(1);
                novoHypnogramaPanel.show(true);
                HypnogramaPainel.show(false);
            } else {
                novoHypnogramaPanel.show(false);
                HypnogramaPainel.show(true);
            }
//            else {
            hipnogramaMenu.setEnabled(true);
            hipnogramaMenu.show(true);
//            }

//            } else {
//                jTabbedPane1.setSelectedIndex(1);
//            }
        } else {
            hipnogramaMenu.setEnabled(false);
            hipnogramaMenu.show(false);
            HypnogramaPainel.show(false);
            StagesPainel.show(false);
        }

        updatePermissions();
    }//GEN-LAST:event_jTabbedPane1StateChanged

    private void SnapToTicksMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SnapToTicksMenuActionPerformed
        if (getEdfFile() != null) {
            polysomnograph.setSnapToTicks(SnapToTicksMenu.getState());
        } else {
            SnapToTicksMenu.setState(false);
        }
    }//GEN-LAST:event_SnapToTicksMenuActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton DWTbutton;
    private javax.swing.JTextField DesvioPadrao;
    private javax.swing.JLabel DesvioPadraoLabel;
    private javax.swing.JPanel Estatatisticas;
    private javax.swing.JButton FFTbutton;
    private javax.swing.JButton FWTbutton;
    private javax.swing.JPanel FerramentasTab;
    private javax.swing.JPanel HypnogramaPainel;
    private javax.swing.JCheckBoxMenuItem InvertedMenu;
    private javax.swing.JLabel MediaAritimeticaLabel;
    private javax.swing.JTextField MediaAritmetica;
    private javax.swing.JComboBox MontagemComboBox;
    private javax.swing.JLabel MontagemLabel;
    private javax.swing.ButtonGroup Montagens;
    private javax.swing.JCheckBoxMenuItem SnapToTicksMenu;
    private javax.swing.JPanel StagesPainel;
    private javax.swing.JLabel Status;
    private javax.swing.JTextField Variancia;
    private javax.swing.JLabel VarianciaLabel;
    private javax.swing.JPanel View;
    private javax.swing.JButton anterior;
    private javax.swing.JCheckBoxMenuItem antiAliasingMenu;
    private javax.swing.JMenuItem carregarScoringMenu;
    private javax.swing.JPanel exibirTab;
    private javax.swing.JMenuItem fecharScoringMenu;
    private javax.swing.JButton fim;
    private javax.swing.JMenu hipnogramaMenu;
    private javax.swing.JPanel hypnogramaTab;
    private javax.swing.JButton inicio;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JPanel novoHypnogramaPanel;
    private javax.swing.JPanel novoPreciseScoringPanel;
    private javax.swing.JMenu opcoesMenu;
    private javax.swing.JButton play;
    private javax.swing.JPanel preciseScoringPanel;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JMenuItem propriedadesMenuItem;
    private javax.swing.JButton proximo;
    private javax.swing.JMenuItem salvarScoringMenu;
    private javax.swing.JMenu scoringMenu;
    private javax.swing.JPanel scoringTab;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JPanel transformadasPainel;
    private javax.swing.JPanel visualizacaoPainel;
    // End of variables declaration//GEN-END:variables
    private final String local;
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
//    novos campos
    private static ResourceBundle resource = new MyResource_BR();
    private EDFFile edfFile = null;

    private String local() {
        String localret = ProjetoTCC2View.class.getName();
        localret = ProjetoTCC2View.class.getResource("/" + localret.replace('.', '/') + ".class").toString();

        if (localret.startsWith("jar:")) {
            localret = localret.substring(4);
            localret = localret.substring(0,localret.lastIndexOf(".jar"));
            localret = localret.substring(0,localret.lastIndexOf("/")+1);

        }

        localret = localret.substring(0, localret.lastIndexOf('/'/*System.getProperty("file.separator")*/) + 1);
        return localret;
    }

    public EDFFile getEdfFile() {
        return edfFile;
    }

    public void setEdfFile(EDFFile edfFile) {
        this.edfFile = edfFile;
    }

    public JEDFHypnogram getHypnogram() {
        return hypnogram;
    }

    public void setHypnogram(JEDFHypnogram hypnogram) {
        this.hypnogram = hypnogram;
    }

    public Polysomnograph getPolysomnograph() {
        return polysomnograph;
    }

    public void setPolysomnograph(Polysomnograph polysomnograph) {
        this.polysomnograph = polysomnograph;
    }

    public static String getVersion() {
        return version;
    }

    public static void setVersion(String version) {
        ProjetoTCC2View.version = version;
    }

    public void displayedRecordModified() {
        if (edfFile == null && hypnogram.isCleared()) {
            return;
        }

        preciseScoring.setFocus(false);
        updateStatusBar();

        polysomnograph.repaint();
        preciseScoring.repaint();
        hypnogram.repaint();

        inicio.setEnabled(!polysomnograph.isItTheBeginning());
        anterior.setEnabled(!polysomnograph.isItTheBeginning());

        fim.setEnabled(!polysomnograph.isItTheEnd());
        proximo.setEnabled(!polysomnograph.isItTheEnd());
        getFrame().repaint();
    }
    private JEDFHypnogram hypnogram = null;
    private JEDFSignalCaption signalCaption = null;
    private Polysomnograph polysomnograph = null;
    private JEDFStagesPanel stagesPanel = null;
    private PreciseScoring preciseScoring = null;
    private static String version = "fEDF";
    private JToggleButton jbPlay = new JToggleButton();
    private ArrayList<Montage> montages = new ArrayList<Montage>(1);
    private Timer playTimer = null;
    private int nummontages = 1;
    private ProjetoTCC2View self = this;

    private void initComponentsCustom() {
        stagesPanel = new JEDFStagesPanel();
        hypnogram = new JEDFHypnogram(this, stagesPanel);
        polysomnograph = new Polysomnograph(this, hypnogram);
        signalCaption = new JEDFSignalCaption(polysomnograph);
        preciseScoring = new PreciseScoring(this, polysomnograph, hypnogram);

        preciseScoring.setVisible(true);

        DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().
                addKeyEventPostProcessor(new KeyboardEventCatcher());

    }

    private void initComponentsAfter() {
        ArrayList<JLabel> jl = new ArrayList<JLabel>();
        for (int i = 0; i < stagesPanel.getComponentCount(); i++) {
            if (stagesPanel.getComponent(i) instanceof JLabel) {
                jl.add((JLabel) stagesPanel.getComponent(i));
            }
        }
        for (JLabel Label : jl) {
            StagesPainel.add(Label);
        }

    }

    public void openFile(File file) {
        try {
            EDFFile newEdfFile = new EDFFile(file);

            if (file.getName().endsWith("edf") || file.getName().endsWith("EDF")) {
                if (getEdfFile() != null) {
                    int op = JOptionPane.showConfirmDialog(null, "Deseja realmente abrir esse arquivo?\n"
                            + "" + file.getName() + ""
                            + "\nIsso irá fechar o arquivo já aberto");
                    if (op != JOptionPane.OK_OPTION || op == JOptionPane.CANCEL_OPTION) {
                        return;
                    }
                }
                try {
                    limpar();
                } catch (Exception e) {
                }
            }
            edfFile = newEdfFile;

            polysomnograph.load(edfFile);
            try {
                hypnogram.loadEDFFile(edfFile);
//                initComponentsAfter();
            } catch (UserCancelException e) {
                // cancelled by user
                //e.printStackTrace();
            }

            jComboBox1 = polysomnograph.getEpochDurationComboBox();
            this.getFrame().setTitle(version + " - " + edfFile.getFileName());

        } catch (FileNotFoundException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(this.getFrame(),
                    getLocalizedString("Unable to access the specified file."),
                    getLocalizedString("Error"), JOptionPane.ERROR_MESSAGE);
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this.getFrame(), getLocalizedString(
                    "The specified file does not appear to be\nan EDF standard compliant file."),
                    getLocalizedString("Error"), JOptionPane.ERROR_MESSAGE);
        } catch (IOException e) {
            JOptionPane.showMessageDialog(this.getFrame(), getLocalizedString(
                    "I/O Error : please verify that you have the rights to access the specified file\nand that it is not in use by another program."),
                    getLocalizedString("Error"), JOptionPane.ERROR_MESSAGE);
        } finally {
        }
        preciseScoring.setVisible(preciseScoring.canBeDisplayed());

        updatePermissions();
        this.getFrame().repaint();
        jTabbedPane1.setSelectedIndex(0);
    }

    public void updatePermissions() {
        hypnogramaTab.setVisible(!hypnogram.isCleared());
        preciseScoring.setVisible(preciseScoring.canBeDisplayed());

        jTabbedPane1.setEnabled(getEdfFile() != null);

//        mainMenu.updatePermissions();
        hipnogramaMenu.setEnabled(getEdfFile() != null);
        scoringMenu.setEnabled(getEdfFile() != null);
        propriedadesMenuItem.setEnabled(getEdfFile() != null);
        setEnabled(jTabbedPane1, (getEdfFile() != null));
        opcoesMenu.setEnabled((getEdfFile() != null));
        updateStatusBar();
    }

    private void setEnabled(Component pan, boolean enabled) {
        if (pan instanceof JTabbedPane) {
            JTabbedPane tab = (JTabbedPane) pan;
            for (int i = 0; i < tab.getComponentCount(); i++) {
                if (tab.getComponent(i) instanceof JPanel) {
                    setEnabled((JPanel) tab.getComponent(i), enabled);
                } else {
                    tab.getComponent(i).setEnabled(enabled);
                }
            }
        } else if (pan instanceof JPanel) {
            JPanel pane = (JPanel) pan;
            for (int i = 0; i < pane.getComponentCount(); i++) {
                if (pane.getComponent(i) instanceof JPanel) {
                    setEnabled((JPanel) pane.getComponent(i), enabled);
                } else {
                    pane.getComponent(i).setEnabled(enabled);
                }
            }
        }
    }

    public void updatePanels() {
        getFrame().repaint();
        signalCaption.repaint();
    }

    public void close() {
        try {
            montages = new ArrayList<Montage>();
            MontagemComboBox.removeAllItems();
            MontagemComboBox.addItem("Nenhuma Montagem");
            nummontages = 1;
            cancelPlayTimer();
            hypnogram.clear();
            if (edfFile != null) {
                edfFile.close();
                edfFile = null;
            }
            polysomnograph.clear();
//            montageToolbar.clear();
            this.getFrame().setTitle(version);
            System.gc();
        } catch (UserCancelException e) {
            // cancelled by user
        } finally {
            updatePermissions();
            this.getFrame().repaint();
        }

    }

    private void cancelPlayTimer() {
        if (jbPlay.isSelected()) {
            jbPlay.doClick();
        }
    }

    @Action
    public void goToNextRecord() {
        polysomnograph.incrementStartRecord();
//        getFrame().repaint();
        updateStatusBar();
    }

    @Action
    public void goToPrevRecord() {
        polysomnograph.decrementStartRecord();
        getFrame().repaint();
        updateStatusBar();
    }

    @Action
    public void goToNextSec() {
        polysomnograph.setStartSecond(polysomnograph.getNavigationSlider().getValue() + 1);
//        getFrame().repaint();
        updateStatusBar();
    }

    @Action
    public void goToPrevSec() {
        polysomnograph.setStartSecond(polysomnograph.getNavigationSlider().getValue() - 1);
        getFrame().repaint();
        updateStatusBar();
    }

    @Action
    public void goToLasttRecord() {
        polysomnograph.lastStartSecond();
//        getFrame().repaint();
        updateStatusBar();
    }

    @Action
    public void goToFirstRecord() {
        polysomnograph.firstStartSecond();
//        getFrame().repaint();
        updateStatusBar();
    }

    @Action
    public void maisZoom() {
//        polysomnograph.setPreferredSize(new Dimension(polysomnograph.getWidth(), polysomnograph.getHeight() * 2));
//        polysomnograph.setBounds(polysomnograph.getX(), polysomnograph.getY(), polysomnograph.getWidth(), polysomnograph.getHeight() * 2);
//        signalCaption.setPreferredSize(new Dimension(signalCaption.getWidth(), polysomnograph.getHeight() * 2));
//        signalCaption.setBounds(signalCaption.getX(), signalCaption.getY(), signalCaption.getWidth(), polysomnograph.getHeight() * 2);
        jPanel1.setPreferredSize(new Dimension(jPanel1.getWidth(), (int) (jPanel1.getHeight() * 1.5)));
        jPanel1.setBounds(jPanel1.getX(), jPanel1.getY(), jPanel1.getWidth(), (int) (jPanel1.getHeight() * 1.5));

//        polysomnograph.setZoom(polysomnograph.getZoom() * 1.5f);
        //        polysomnograph.zoomIn();
        polysomnograph.repaint();
        updatePanels();
    }

    @Action
    public void menosZoom() {
//        polysomnograph.setPreferredSize(new Dimension(polysomnograph.getWidth(), polysomnograph.getHeight() / 2));
//        polysomnograph.setBounds(polysomnograph.getX(), polysomnograph.getY(), polysomnograph.getWidth(), polysomnograph.getHeight() / 2);

        jPanel1.setPreferredSize(new Dimension(jPanel1.getWidth(), (int) (jPanel1.getHeight() / 1.5)));
        jPanel1.setBounds(jPanel1.getX(), jPanel1.getY(), jPanel1.getWidth(), (int) (jPanel1.getHeight() / 1.5));

//        polysomnograph.setZoom(polysomnograph.getZoom() / 2f);
        //        polysomnograph.zoomOut();
//        getFrame().repaint();
        polysomnograph.repaint();
        updatePanels();
    }

    @Action
    public void maisAmpl() {
        polysomnograph.zoomIn();
        updatePanels();
    }

    @Action
    public void menosAmpl() {
        polysomnograph.zoomOut();
        updatePanels();
    }

    @Action
    public void resetAmpl() {
        polysomnograph.zoomReset();
        updatePanels();
    }

    @Action
    public void resetZoom() {
        jPanel1.setPreferredSize(new Dimension(jScrollPane1.getWidth(), jScrollPane1.getHeight() / 2));
        jPanel1.setBounds(jPanel1.getX(), jPanel1.getY(), jScrollPane1.getWidth(), jScrollPane1.getHeight() / 2);

        polysomnograph.setZoom(0);
        getFrame().repaint();
        updatePanels();
    }

    @Action
    public void Info() {
        new EDFInformationDialog(this);
    }

    @Action
    public void assignNewMontage() {
        try {

            NewMontageDialog newMontageDialog = new NewMontageDialog(getFrame(), getMontages());
            Montage mon = newMontageDialog.getNewMontage();

            if (mon != null) {
                getMontages().add(mon);
                MontagemComboBox.addItem("Montagem: " + nummontages++);

                MontagemComboBox.setSelectedIndex(MontagemComboBox.getItemCount() - 1);
                MontagemComboBoxActionPerformed(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Action
    public void loadDefaultmontage() {

        polysomnograph.loadMontage(Montage.getDefaultMontage());
    }

    @Action
    public void removerMontagem() {
        try {
            if (getMontages().size() > 0) {
                getMontages().remove(MontagemComboBox.getSelectedIndex() - 1);
                MontagemComboBox.removeItemAt(MontagemComboBox.getSelectedIndex());
            }
        } catch (ArrayIndexOutOfBoundsException a) {
        }
    }

    @Action
    public void onButtonPress(int i) {
        try {
            if (getMontages().get(i) == null) {
                NewMontageDialog newMontageDialog = new NewMontageDialog(getFrame(), getMontages());
                getMontages().add(i, newMontageDialog.getNewMontage());
                polysomnograph.loadMontage(getMontages().get(i));
            } else {
                polysomnograph.loadMontage(getMontages().get(i));
            }
//        newMontageDialog.assignNewMontage();
        } catch (IndexOutOfBoundsException e) {
            NewMontageDialog newMontageDialog = new NewMontageDialog(getFrame(), getMontages());
            getMontages().add(i, newMontageDialog.getNewMontage());
            polysomnograph.loadMontage(getMontages().get(i));
        }
        getFrame().repaint();
    }

    @Action
    public void updateStatusBar() {
        if (edfFile == null) {
            Status.setText("Ready");
            return;
        }

        int epochNumber = (int) Math.round((double) polysomnograph.getStartSecond() / (double) edfFile.getRecordDuration()); //(double)polysomnograph.getNbSecondsToDisplay());
        int totEpoch = (int) Math.round((double) edfFile.getTotalDuration() / (double) edfFile.getRecordDuration()); //(double)polysomnograph.getNbSecondsToDisplay());
        epochNumber++;

        Calendar epochTime = edfFile.getStartTime();
        DateFormat dateFormat = DateFormat.getDateTimeInstance();

        epochTime.add(Calendar.SECOND, polysomnograph.getStartSecond());
        String startTime = dateFormat.format(epochTime.getTime());

        dateFormat = DateFormat.getTimeInstance();
        epochTime.add(Calendar.SECOND, polysomnograph.getEpochDuration());
        String endTime = dateFormat.format(epochTime.getTime());

        String statusText = getLocalizedString("Epoch n° ") + epochNumber + "/" + totEpoch + "        " + startTime + " -> " + endTime;

        if (!hypnogram.isCleared()) {
            statusText += getLocalizedString("                 Hypnogram Epoch Duration : ") + hypnogram.getEpochDuration();
        }

        Status.setText(statusText);
    }

    @Action
    public void FWTCoiflet() {
        polysomnograph.showfwt();
    }

    @Action
    public void DWTCoiflet() {
        polysomnograph.showdwt();
    }

    @Action
    public void Wavelet() {
        polysomnograph.showWavelet();
    }

    @Action
    public void WaveletDaubechies() {
        polysomnograph.showWaveletDaubechies();
    }

    @Action
    public void Play() {
//        ResourceMap res = getResourceMap();
        if (playTimer != null) {
            if (playTimer.isRunning()) {
                play.setIcon(getResourceMap().getIcon("Play.Action.icon"));
                play.setText("Play");
                playTimer.stop();
                playTimer = null;
            }
        } else {
            play.setText("Pause");
            play.setIcon(getResourceMap().getIcon("Stop.Action.icon"));
            playTimer = new Timer(250, new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    if (!polysomnograph.isItTheEnd()) {
                        polysomnograph.setStartSecond(polysomnograph.getNavigationSlider().getValue() + 1);
                    }
                }
            });
            playTimer.setRepeats(true);
            playTimer.start();
        }
    }

    @Action
    public void exportarEdfParaTexto() {
        new EDFSignalToTextDialog(this, polysomnograph);
    }

    @Action
    public void exportarAnaliseFFT() {
        new FFTExportDialog(this, polysomnograph);
    }

    @Action
    public void limpar() {
        try {
            montages = new ArrayList<Montage>();
            while (MontagemComboBox.getItemCount() > 1) {
                MontagemComboBox.removeItemAt(1);
            }
//            MontagemComboBox.addItem("Nenhuma Montagem");
            nummontages = 1;
            cancelPlayTimer();
            hypnogram.clear();
            if (edfFile != null) {
                edfFile.close();
                edfFile = null;
            }
            polysomnograph.clear();
//            montageToolbar.clear();
            this.getFrame().setTitle(version);
            System.gc();
            this.getFrame().repaint();
        } catch (UserCancelException e) {
//            e.printStackTrace();
            // cancelled by user
        } finally {
            updatePermissions();
            this.getFrame().repaint();
        }
    }

    @Action
    public void refresh() {

        updatePermissions();
        this.getFrame().repaint();
        hypnogram.repaint();


    }

    /**
     * @return the DesvioPadrao
     */
    public javax.swing.JTextField getDesvioPadrao() {
        return DesvioPadrao;
    }

    /**
     * @param DesvioPadrao the DesvioPadrao to set
     */
    public void setDesvioPadrao(javax.swing.JTextField DesvioPadrao) {
        this.DesvioPadrao = DesvioPadrao;
    }

    /**
     * @return the MediaAritmetica
     */
    public javax.swing.JTextField getMediaAritmetica() {
        return MediaAritmetica;
    }

    /**
     * @param MediaAritmetica the MediaAritmetica to set
     */
    public void setMediaAritmetica(javax.swing.JTextField MediaAritmetica) {
        this.MediaAritmetica = MediaAritmetica;
    }

    /**
     * @return the VarianciaLabel
     */
    public javax.swing.JTextField getVariancia() {
        return Variancia;
    }

    /**
     * @param VarianciaLabel the VarianciaLabel to set
     */
    public void setVariancia(javax.swing.JTextField Variancia) {
        this.Variancia = Variancia;
    }

    /**
     * @return the montages
     */
    public ArrayList<Montage> getMontages() {
        return montages;
    }

    /**
     * @param montages the montages to set
     */
    public void setMontages(ArrayList<Montage> montages) {
        this.montages = montages;
    }

    /**
     * @return verdadeiro se estiver invertido
     */
    public boolean getsignalInverted() {
        return InvertedMenu.getState();
    }

    private class KeyboardEventCatcher implements KeyEventPostProcessor {

        /* (non-Javadoc)
         * @see java.awt.KeyEventPostProcessor#postProcessKeyEvent(java.awt.event.KeyEvent)
         */
        public boolean postProcessKeyEvent(KeyEvent arg0) {

            if (edfFile == null) {
                return false;
            }
            if (DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() != self.getFrame()) {
                return false;
            }

            if (arg0.getID() == KeyEvent.KEY_PRESSED) {
//                JOptionPane.showMessageDialog(null, "affe " + arg0);
                switch (arg0.getKeyCode()) {

                    case KeyEvent.VK_LEFT:
                        if (polysomnograph.isSnapToTicks()) {
                            goToPrevRecord();
                        } else {
                            goToPrevSec();
                        }
                        break;
                    case KeyEvent.VK_RIGHT:
                        if (polysomnograph.isSnapToTicks()) {
                            goToNextRecord();
                        } else {
                            goToNextSec();
                        }
                        break;

                    case KeyEvent.VK_HOME:
                        goToFirstRecord();
                        break;
                    case KeyEvent.VK_END:
                        goToLasttRecord();
                        break;

                    case KeyEvent.VK_UP:
                        preciseScoring.nextPosition();
                        break;
                    case KeyEvent.VK_DOWN:
                        preciseScoring.previousPosition();
                        break;
                    case KeyEvent.VK_SPACE:
                        preciseScoring.setCustomText();
                        break;
                }

                switch (arg0.getKeyChar()) {
                    case '.':
                    case 'm':
                    case 'M':
                        hypnogram.setStageMVT();
                        break;
                    case 'p':
                    case 'P':
                        preciseScoring.setStatePV();
                        break;
                    case 'f':
                    case 'F':
                    case 's':
                    case 'S':
                        preciseScoring.setStateFx();
                        break;
                    case 'd':
                    case 'D':
                    case 't':
                    case 'T':
                        preciseScoring.setStateST();
                        break;
                    case 'k':
                    case 'K':
                        preciseScoring.setStateKCX();
                        break;
                    case '+':
                    case '=':
                        preciseScoring.duplicatePreviousScore();
                        break;

                    case '0':
                        hypnogram.setStageWAKE();
                        break;
                    case '1':
                        hypnogram.setStage1();
                        break;
                    case '2':
                        hypnogram.setStage2();
                        break;
                    case '3':
                        hypnogram.setStage3();
                        break;
                    case '4':
                        hypnogram.setStage4();
                        break;
                    case '5':
                    case 'r':
                    case 'R':
                        hypnogram.setStageREM();
                        break;
                    case '6':
                    case 'u':
                    case 'U':
                        hypnogram.setStageUnscored();
                        break;
                    case '7':
                    case 'o':
                    case 'O':
                        preciseScoring.setStateVYO();
                        break;
                    case '8':
                    case 'c':
                    case 'C':
                        preciseScoring.setStateVYF();
                        break;
                    case '9':
                    case 'a':
                    case 'A':
                        preciseScoring.setStateART();
                        break;
                }
            }
            cancelPlayTimer();
            return false;
        }
    }

    @Action
    public void salvarHypnograma() {
        new HypnogramToTextDialog(this, hypnogram);
    }

    @Action
    public void fecharHypnograma() {
        try {
            hypnogram.clear();
            novoHypnogramaPanel.show(true);
            HypnogramaPainel.show(false);
        } catch (UserCancelException e) {
            // user has cancelled his action
        } finally {
            updatePermissions();
        }
    }

    @Action
    public void novoHypnograma() {
        if (getEdfFile() != null) {
            try {

                new NewHypnogramDialog(this, polysomnograph, hypnogram, false);

                novoHypnogramaPanel.show(hypnogram.isCleared());
                HypnogramaPainel.show(!hypnogram.isCleared());

            } catch (NullPointerException e) {
                // cancelled by user
            } finally {
                updatePermissions();
                this.getFrame().repaint();
            }
        }
    }

    @Action
    public void carregarHypnograma() {
        try {

            new NewHypnogramDialog(this, polysomnograph, hypnogram, true);

            novoHypnogramaPanel.show(hypnogram.isCleared());
            HypnogramaPainel.show(!hypnogram.isCleared());

        } catch (NullPointerException e) {
            // cancelled by user
        } finally {
            updatePermissions();
            this.getFrame().repaint();
        }
    }

    @Action
    public void novoPreciseScoring() {
        try {
            new NewPreciseScoringDialog(this, preciseScoring, false);

            novoPreciseScoringPanel.show(preciseScoring.isCleared());
            preciseScoringPanel.show(!preciseScoring.isCleared());

            jTabbedPane1.setSelectedIndex(2);

            preciseScoringPanel.repaint();

            this.getFrame().repaint();
        } catch (NullPointerException e) {
            // cancelled by user
        } finally {
            updatePermissions();
            this.getFrame().repaint();
        }
        updatePermissions();
    }

    @Action
    public void carregarScoring() {
        new NewPreciseScoringDialog(this, preciseScoring, true);

        novoPreciseScoringPanel.show(preciseScoring.isCleared());
        preciseScoringPanel.show(!preciseScoring.isCleared());

        jTabbedPane1.setSelectedIndex(2);

        preciseScoringPanel.repaint();

        this.getFrame().repaint();
        updatePermissions();
    }

    @Action
    public void salvarScoring() {
        new PreciseScoringToTextDialog(this, preciseScoring);
    }

    @Action
    public void fecharScoring() {
        preciseScoring.clear();

        novoPreciseScoringPanel.show(preciseScoring.isCleared());
        preciseScoringPanel.show(!preciseScoring.isCleared());

        novoPreciseScoringPanel.repaint();
        this.getFrame().repaint();
        updatePermissions();
    }

    @Action
    public void ajudaAtalhosDoTeclado() {
        new JEDFHelpDialog(this);
    }
}
